package com.niguang.file.servie.impl;

import com.alibaba.fastjson.JSONObject;
import com.niguang.common.util.HttpClientUtil;
import com.niguang.file.servie.FileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class FileServiceImpl implements FileService {

    @Value("${file.basePath}")
    private String filePath;

    @Value("${root.web.url}")
    private String rootWebUrl;


    @Override
    public List<JSONObject> uploadFile(MultipartFile[] multipartFile) {
        List<JSONObject> url = new ArrayList<>();
        for (MultipartFile file : multipartFile) {
            String uploadImage = HttpClientUtil.uploadImage(file, "", "wechat");
            JSONObject jsonObject = new JSONObject(1);
            jsonObject.put("url", uploadImage);
            url.add(jsonObject);
        }
        return url;
    }

    @Override
    public List<JSONObject> uploadFileBase64(String[] fileBase64) {
        List<JSONObject> url = new ArrayList<>();
        for (String file : fileBase64) {
            String uploadImage = HttpClientUtil.uploadImage(file, "", "work");
            JSONObject jsonObject = new JSONObject(1);
            jsonObject.put("url", uploadImage);
            url.add(jsonObject);
        }
        return url;
    }

}
